package com.citicpub_cloud.restfull.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.citicpub_cloud.restfull.api.dto.TbAdminAccountExt;
import com.citicpub_cloud.restfull.common.constant.EnumConstant;
import com.citicpub_cloud.restfull.dao.AdminAccountDaoService;
import com.citicpub_cloud.restfull.service.AdminUserService;
import com.citicpub_cloud.restfull.utils.PasswordEncoder;

@Service
public class AdminUserServiceImpl implements AdminUserService {
	
	@Autowired
	private AdminAccountDaoService adminAccountDaoService;

	@Override
	public TbAdminAccountExt login(String loginName, String password) {
		// TODO Auto-generated method stub
		List<TbAdminAccountExt> userAccountList = adminAccountDaoService.selectByLoginName(loginName);
        if(null!=userAccountList && userAccountList.size()>0){
        	TbAdminAccountExt tbUserAccount = userAccountList.get(0);
        	if (null != tbUserAccount) {
				String mpass = tbUserAccount.getPassword();
				boolean ret = PasswordEncoder.verify(password, EnumConstant.CipherAlgorithm.SHA1, mpass);
				if (ret) {
					return tbUserAccount;
				}
			}
        }
        return null;
	}

}
